<?php

class Home extends Controller {
	
	function Home()
	{
		parent::Controller();
		$this->load->model('Product_model');
		$this->load->model('Product_image_model');
	}
	
	function index() {
		$ary_where = array();

		$total_rows = $this->Product_model->countProduct($ary_where);
		$per_page = '3';
		$this->pagination->initialize(array(
			'base_url'=>base_url().'index.php/home/index/',
			'total_rows'=>$total_rows,
			'per_page'=>$per_page,
		));
		$paging = array(
			'per_page'=>$per_page,
			'limit'   =>($this->uri->segment(3)=='')?'0':$this->uri->segment(3),
		);
		
		$product_info = $this->Product_model->getProducts($ary_where, $paging);
		
		foreach ($product_info as $key => $value) {
			$product_info[$key]['image'] = $this->Product_image_model->getProduct_image(array('product_id'=>$value['id']));	
		}

		$data['paging'] = $this->pagination->create_links();		
		$data['product_info'] = $product_info;
		$data['inc_script'] = '<script type="text/javascript" src="'.base_url().'js/home.js"></script>';
		$this->load->view('home_view',$data);
	}
	
	function detail() {
		$id = $this->uri->segment(3);
		$ary_where = array('p.id'=>$id);
		$product_info = $this->Product_model->getProductdetail($ary_where);
		$product_info['image'] = $this->Product_image_model->getProduct_image(array('product_id'=>$id));	

		//var_dump($product_info);
		//exit;
		$data['product_info'] = $product_info;
		$data['inc_script'] = '';
		$this->load->view('product_detail_view',$data);
	}
}